<%@ LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%
'///////////////////////////////////////////////////////////////////////////////
'// 插件应用:    Z-Blog 1.8 Devo
'// 插件制作:    haphic(http://haphic.com)
'// 备    注:    DeepEyes 参数设定
'// 最后修改：   2008-2-9
'// 最后版本:    0.4
'///////////////////////////////////////////////////////////////////////////////
%>
<% Option Explicit %>
<% On Error Resume Next %>
<% Response.Charset="UTF-8" %>
<% Response.Buffer=True %>
<!-- #include file="../../../../c_option.asp" -->
<!-- #include file="../../../../function/c_function.asp" -->
<!-- #include file="../../../../function/c_function_md5.asp" -->
<!-- #include file="../../../../function/c_system_lib.asp" -->
<!-- #include file="../../../../function/c_system_base.asp" -->
<!-- #include file="../../../../function/c_system_plugin.asp" -->
<!-- #include file="../../../../function/c_system_event.asp" -->
<!-- #include file="../../../../plugin/p_config.asp" -->
<%
'---------------------------------------------------------
Const Couple_Version="1.0.2 Beta"
'---------------------------------------------------------
%>
<%
Call System_Initialize()

'检查是否启用
If Not LCase(ZC_BLOG_THEME)=LCase("Couple") Then Call ShowError(48) 

Dim strDomain
strDomain = Request.ServerVariables("SERVER_NAME")
'strDomain = Request.ServerVariables("HTTP_HOST")

Dim strAct
strAct = Request.QueryString("act")

Dim tmpSng 
Dim strOutPut
Dim strResult
Dim strVersion

Select Case strAct

	Case "ping"

		If ReQuest.QueryString("mode")="fmode" Then
			tmpSng=LoadFromFile(BlogPath & "/THEMES/"& ZC_BLOG_THEME &"/PLUGIN/config.asp","utf-8")
			Call SaveValueForSetting(tmpSng,True,"String","Couple_VerifyCode","")
			Call SaveToFile(BlogPath & "/THEMES/"& ZC_BLOG_THEME &"/PLUGIN/config.asp",tmpSng,"utf-8",False)
			Call SaveToFile(BlogPath & "THEMES/"& ZC_BLOG_THEME &"/PLUGIN/REGISTER/VerifyNumber"&ZC_BLOG_CLSID&".html","","utf-8",False)
		End If

		strOutPut = strOutPut & "<p style=""float:right;""><a href=""javascript:void(0)"" onclick=""regClose()""><img src="""& ZC_BLOG_HOST &"themes/"& ZC_BLOG_THEME &"/style/default/closebig.png"" /></a></p>"

		strOutPut = strOutPut & "<p style=""font-size:21px;color:#FDD;"">您正在使用的情侣主题需要验证!</p>"
		strOutPut = strOutPut & "<p style=""font-size:15px;"">如果您不是授权用户, 也可无限制的使用本主题的全部功能, 只是会在每次进入后台时出现验证提示.<br/>"
		strOutPut = strOutPut & "非授权用户请勿擅自修改主题功能, 如因此导致博客出现问题, 后果自负!<br/>"
		strOutPut = strOutPut & "授权用户如想自定义主题, 请根据授权级别联系主题作者 (haphic@gmail.com) 协助.<br/>&nbsp;<br/>"
		strOutPut = strOutPut & "[<a href="""& Couple_RegHost &"/licence"" target=""_blank"" style=""font-size:15px;text-decoration:underline;color:#DDF;"">完整主题使用协议</a>]</p>"

		strOutPut = strOutPut & "<form method=""post"" target=""_self"" action="""& ZC_BLOG_HOST &"themes/"& ZC_BLOG_THEME &"/plugin/register.asp?act=reg"">"

		strResult=getHTTPPage(Couple_RegHost &"Themes/CoupleReg/CoupleReg.asp?a=ping&u="&Server.URLEncode(strDomain))
		If InStr(strResult,"<!--Ready!-->")>0 Then
			strOutPut = strOutPut & strResult
			strOutPut = strOutPut & "<p style=""color:#8F8;"">服务器连接正常, 您可以开始验证步骤!</p>"
			strOutPut = strOutPut & "<p style=""font-size:18px;"">您的域名:</p>"
			strOutPut = strOutPut & "<p style=""font-size:18px;""><input type=""text"" id=""regName"" name=""regName"" value="""& strDomain &""" style=""height:30px;width:400px;padding:3px;font-size:24px;border:1px solid #FFF;"" disabled=""disabled""/></p>"
			strOutPut = strOutPut & "<p style=""font-size:18px;"">您的授权码:(<a href="""& Couple_RegHost &"/order"" target=""_blank"" style=""font-size:18px;text-decoration:underline;color:#DDF;"">购买主题</a>)</p>"
			strOutPut = strOutPut & "<p style=""font-size:18px;""><input type=""text"" id=""regKey"" name=""regKey"" value="""" style=""height:30px;width:400px;padding:3px;font-size:24px;border:1px solid #FFF;""/></p>"
			strOutPut = strOutPut & "<p class=""reg-button"" style=""font-size:18px;""><input type=""checkbox"" name=""regAgree""  id=""regAgree"" onclick=""if(this.checked){document.getElementById('regSubmit').disabled=false}else{document.getElementById('regSubmit').disabled=true}""/><label for=""regAgree"" style=""font-size:18px;"">我同意主题使用协议</label> [<a href="""& Couple_RegHost &"/licence"" target=""_blank"" style=""font-size:18px;text-decoration:underline;color:#DDF;"">阅读协议</a>]</p>"
			strOutPut = strOutPut & "<p class=""reg-button"" style=""font-size:18px;""><input type=""submit"" id=""regSubmit"" value=""提交验证"" style=""height:34px;width:150px;padding:3px;font-size:18px;border:3px double #88F;"" onclick=""return regVerify()"" disabled=""disabled""/> <input type=""button"" value=""下次再说"" style=""height:34px;width:150px;padding:3px;font-size:18px;border:3px double #88F;"" onclick=""regClose()""/></p>"
		Else
			strOutPut = strOutPut & "<p style=""color:#F88;"">服务器连接失败, 可能是您主机有限制或验证服务器未开放.</p>"
			strOutPut = strOutPut & "<p style=""color:#F88;""><a href="""& Couple_RegHost &""" target=""_blank"" style=""text-decoration:underline;color:#DDF;"">请点此确认验证服务器可以访问</a>, 如果不能, 请稍候重试!</p>"
			strOutPut = strOutPut & "<p style=""color:#F88;"">如果服务器正常开放, 请联系您的主机商解决您主机无法访问站外的问题. <br/>或联系主题作者 (haphic@gmail.com) 获取其它版本, 或放弃验证(不影响正常使用).</p>"
		End If
		strOutPut = strOutPut & "</form>"

	Case "reg"
		strResult=getHTTPPage(Couple_RegHost &"Themes/CoupleReg/CoupleReg.asp?u="&Server.URLEncode(strDomain)&"&k="& MD5(Trim(ReQuest.Form("regKey"))))

		If InStr(strResult,"<!--Authorized-->")>0 Then
			tmpSng=LoadFromFile(BlogPath & "/THEMES/"& ZC_BLOG_THEME &"/PLUGIN/config.asp","utf-8")
			Call SaveValueForSetting(tmpSng,True,"String","Couple_VerifyCode",Trim(ReQuest.Form("regKey")))
			Call SaveToFile(BlogPath & "/THEMES/"& ZC_BLOG_THEME &"/PLUGIN/config.asp",tmpSng,"utf-8",False)
			Call SaveToFile(BlogPath & "THEMES/"& ZC_BLOG_THEME &"/PLUGIN/REGISTER/VerifyNumber"&ZC_BLOG_CLSID&".html",MD5(strDomain & Trim(ReQuest.Form("regKey"))),"utf-8",False)
			strOutPut = strOutPut & "<p class=""reg-result"" style=""font-size:18px;font-weight:bold;color:#AFA;"">"& strResult &"</p>"
			strOutPut = strOutPut & "<script type=""text/javascript"">$('#verifyHint,p.reg-button').hide();</script>"
			strOutPut = strOutPut & "<p style=""font-size:15px;font-weight:bold;color:#FDD;"">此提示将不会再次出现. Enjoy!</p>"
			strOutPut = strOutPut & "<p><input type=""button"" value=""点此关闭"" style=""height:34px;width:150px;padding:3px;font-size:18px;border:3px double #88F;"" onclick=""regClose()""/></p>"
		ElseIf InStr(strResult,"<!--unAuthorized-->")>0 Then
			strOutPut = strOutPut & "<p class=""reg-result"" style=""font-size:18px;font-weight:bold;color:#FAA;"">"& strResult &"</p>"
		Else
			strOutPut = strOutPut & "<p class=""reg-result"" style=""font-size:18px;font-weight:bold;color:#FAA;"">服务器未能返回验证结果, 请重试!</p>"
		End If

	Case "update"
		strResult=getHTTPPage(Couple_RegHost &"Themes/CoupleReg/CoupleReg.asp?a=update&u="&Server.URLEncode(strDomain)&"&k="& MD5(Couple_VerifyCode))

		strOutPut = strOutPut & "<p style=""float:right;""><a href=""javascript:void(0)"" onclick=""regClose()""><img src="""& ZC_BLOG_HOST &"themes/"& ZC_BLOG_THEME &"/style/default/closebig.png"" /></a></p>"

		If Not strResult=False Then

			If InStr(strResult,"{%")>0 And InStr(strResult,"%}")>0 Then
				strVersion = Mid(strResult,InStr(strResult,"{%")+2,InStr(strResult,"%}")-InStr(strResult,"{%")-2)
				If LCase(strVersion)=LCase(Couple_Version) Then
					strOutPut = strOutPut & "<p style=""font-size:18px;font-weight:bold;color:#AFA;"">您的主题已是最新版!</p>"
				Else
					strOutPut = strOutPut & "<p style=""font-size:18px;font-weight:bold;color:#FAA;"">您的主题不是最新版, 最新版为: "& strVersion &". <br/>请联系主题作者 (haphic@gmail.com) 取得最新版本!</p>"
				End If
			Else
				strOutPut = strOutPut & "<p style=""font-size:18px;font-weight:bold;color:#FAA;"">服务器未能返回正确版本信息!</p>"
			End If
			
			strOutPut = strOutPut & "<hr style=""visibility:visible;height:2px;background-color:#91ADBF;border:none;""/>"

			If InStr(strResult,"<!--Authorized-->")>0 Then
				strOutPut = strOutPut & "<p style=""font-size:18px;font-weight:bold;color:#AFA;"">"& strResult &"</p>"
			ElseIf InStr(strResult,"<!--unAuthorized-->")>0 Then
				strOutPut = strOutPut & "<p style=""font-size:18px;font-weight:bold;color:#FAA;"">主题授权校验失败. <a href="""& Couple_RegHost &"/order"" target=""_blank"" style=""font-size:18px;color:#DDF;"">(购买主题)</a>"
				strOutPut = strOutPut & "<br/>"& strResult &"</p>"
			Else
				strOutPut = strOutPut & "<p style=""font-size:18px;font-weight:bold;color:#FAA;"">服务器未能返回正确验证结果!</p>"
			End If

		Else

			strOutPut = strOutPut & "<p style=""font-size:18px;font-weight:bold;color:#FAA;"">服务器未能返回数据, 请重试!</p>"

		End If


	Case Else
		strOutPut = strOutPut & "<p class=""reg-result"">提交数据异常, 请联系主题作者并提供您的操作步骤.</p>"


End Select

Response.Write strOutPut

'*********************************************************
' 目的：    取得目标网页的html代码(备用)
'*********************************************************
Function getHTTPPage(url)
On Error Resume Next
Dim Http
Dim SiteResolve,SiteConnect,SiteSend,SiteReceive '超时设置，单位：秒
SiteResolve=5 '解析地址（DNS）超时时间
SiteConnect=5 '链接超时时间
SiteSend=4 '发送请求时间
SiteReceive=10 '等待响应时间
Dim j
For j=0 To 2
	Set Http=server.createobject("Msxml2.ServerXMLHTTP")
	Http.setTimeouts SiteResolve*1000,SiteConnect*1000,SiteSend*1000,SiteReceive*1000
	Http.open "GET",url,False
	Http.send()

	If http.Status=200 Then
		getHTTPPage=Http.responseText
		Set http=Nothing
		Exit For
	Else
		getHTTPPage=False
		Set http=Nothing
	End If

Next
Err.Clear
End Function
'*********************************************************

Call System_Terminate()

If Err.Number<>0 then
  Call ShowError(0)
End If
%>

